package org.example.wx.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.common.utils.ResponseUtil;
import org.example.wx.dto.GoodsOrderGeneralDto;
import org.example.wx.dto.OrderDto;
import org.example.wx.service.WxOrderService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "微信订单")
@RequestMapping("/wx/order")
public class WxOrderController {

    WxOrderService wxOrderService;

    public WxOrderController(WxOrderService wxOrderService) {
        this.wxOrderService = wxOrderService;
    }

    @PostMapping("/post")
    @ApiOperation("下订单")
    public Object postOrder(@RequestBody List<OrderDto> orderList){

        wxOrderService.addOrder(orderList);
        return ResponseUtil.ok();
    }


    @GetMapping("/list")
    @ApiOperation("获得订单列表")
    public Object list(@RequestParam(defaultValue = "all") String type){

        List<GoodsOrderGeneralDto> list = wxOrderService.list(type);
        return ResponseUtil.ok(list);
    }

    @GetMapping("/confirm")
    @ApiOperation("确认订单")
    public Object confirm(@RequestParam Long orderId){

        wxOrderService.confirm(orderId);
        return ResponseUtil.ok();
    }
}
